package com.hyh;


import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import redis.clients.jedis.Jedis;

import java.util.Map;

public class test {

    private Jedis jedis;

    @BeforeEach
    void setUp() {
        // 建立连接
        jedis = new Jedis("192.168.18.130", 6379);
        // 设置密码
        jedis.auth("123456");
        // 选择数据库
        jedis.select(0);
        System.out.println("连接成功");

    }

    @Test
    public void test() {

        String result = jedis.set("name", "王五");
        System.out.println("result  = " + result);
        //获取数据
        jedis.get("name");


    }


    @Test
    public void testHas() {
        jedis.hset("user:1", "name", "lisi");
        jedis.hset("user:1", "age", "20");
        jedis.hset("user:2", "name", "zhaogou");
        jedis.hset("user:2", "age", "22");
        //获取
        Map<String, String> map = jedis.hgetAll("user:2");
        System.out.println(map);
    }


    @AfterEach
    void tearDown() {
        if (jedis != null) {
            jedis.close();
        }


    }


}
